/*创建ajax对象兼容写法*/
var getXHR=function(){
    var list=[function(){
        return new XMLHttpRequest;
    },function(){
        return new ActiveXObject("Microsoft.XHMHTTP");
    },function(){
        return new ActiveXObject("Msxml2.XHMHTTP");
    },function(){
        return new ActiveXObject("Msxml3.XHMHTTP");
    }];
    var temp=null;
    for(var i=0;i<list.length;i++){
        try{
            temp=list[i]();
        }catch(e){
            continue;
        }
        getXHR=list[i];
        break;
    }
    if(!temp){
        throw new Error("您当前的浏览器不支持Ajax，请更新浏览器");
    }
    return temp;
}

/*js防抖动*/
var debounce = function (func, threshold, execAsap) {  
    var timeout;  
    return function debounced () {  
        var obj = this, args = arguments;  
        function delayed () {  
            if (!execAsap)  
            func.apply(obj, args);  
            timeout = null;  
        };  
        if (timeout)  
            clearTimeout(timeout);  
        else if (execAsap)  
            func.apply(obj, args);  
        timeout = setTimeout(delayed, threshold || 100);  
    };  
}

/*js绑定事件兼容*/
var addEvent = function(element,type,callback){
    if(element.addEventListener){
        element.addEventListener(type,callback,false);
    }else if(element.attachEvent){
        element.attachEvent('on' + type,callback)
    }
}

/*移除事件*/
var removeEvent=function(element,type,handler) {
    if (element.removeEventListener) {
         element.removeEventListener(type,handler,false); 
    }else if (element.datachEvent) { 
         element.datachEvent('on' + type,handler); 
    }else{
         element['on' + type] = null;
    }
}

/*阻止事件冒泡*/
var stopPropagation=function(ev) { 
    if (ev.stopPropagation) { 
         ev.stopPropagation(); 
    }else { 
         ev.cancelBubble = true;
    }
}

function stopBubble(event) {
    // 如果提供了事件对象，则这是一个非IE浏览器
    if ( event && event.stopPropagation ) {

        // 因此它支持W3C的stopPropagation()方法 

        event.stopPropagation();

    } else {

        // 否则，我们需要使用IE的方式来取消事件冒泡

        window.event.cancelBubble = true;
    }
}